﻿<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title></title>
    <link rel="stylesheet" href="bs/css/bootstrap.css">
    <style>
        body{
            background-color: #e8e8e8;
        }
    </style>
</head>
<body>
    <div id="app">
        <div class="row">
            <div class="col-xs-8 col-xs-offset-2">
                <div class="page-header">
                    <h1>VueRouter</h1>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-xs-2 col-xs-offset-2">
                <div class="list-group">
                    <!-- 使用 router-link 组件来导航. -->
                    <!-- 通过传入 `to` 属性指定链接. -->
                    <!-- <router-link> 默认会被渲染成一个 `<a>` 标签 -->
                    <router-link class="list-group-item"  to="/home">首页</router-link>
                    <router-link class="list-group-item"  to="/nowplaying">正在热映</router-link>
                    <router-link class="list-group-item"  to="/comingsoon">即将上映</router-link>
                </div>
            </div>
            <div class="col-xs-6">
                <div class="panel">
                    <div class="panel-body">
                        <!-- 路由出口 -->
                        <!-- 路由匹配到的组件将渲染在这里 -->
                        <router-view></router-view>
                    </div>
                </div>
            </div>
        </div>
    </div>


    <template id="home">
        <div>
            <h2>首页</h2>
            <p>这是我的首页</p>
            <img src="img/home.png" alt="" width="250">
        </div>
    </template>

    <template id="nowplaying">
        <div>
            <h2>正在热映</h2>
            <p>X战警：黑凤凰</p>
            <img src="img/01.jpg" alt="" width="250">
        </div>
    </template>

    <template id="comingsoon">
        <div>
            <h2>即将上映</h2>
            <p>即将上映!</p>
            <img src="img/02.jpg" alt="" width="250">
        </div>
    </template>

    <script src="js/vue.js"></script>
    <script src="js/vue-router.js"></script>
    <script>
        // 1.创建组件
        const  Home = Vue.extend({
            template: '#home'
        });

        const  nowPlaying = Vue.extend({
            template: '#nowplaying'
        });

        const  comingSoon = Vue.extend({
            template: '#comingsoon'
        });

        // 2. 定义路由
        const routes = [
            {path:'/home', component: Home},
            {path:'/nowplaying', component: nowPlaying},
            {path:'/comingsoon', component: comingSoon},
            // 配置根路由
            {path:'/', redirect: '/home'}
        ];

        // 3. 创建路由实例
        const router = new VueRouter({
            routes
        });

        // 4.创建Vue的实例,并挂载
        new Vue({
            router
        }).$mount('#app')
    </script>
</body>
</html>